
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui"
	xmlns:c="http://java.sun.com/jsp/jstl/core">

<ui:composition template="/template_padrao.xhtml">
	<ui:define name="content">

		<f:event type="preRenderView" listener="#{obraMB.beginConversation()}" />


		<h2>Consulta Obras</h2>

		<h:form id="form_consulta_obra">

			<p:fieldset>
				<legend>Pesquisa</legend>

				<div id="actionButton" class="buttonNew">
					<p:commandButton value="Novo" 
									action="#{obraMB.novo()}"
									ajax="false" 
									id="btNovaObra" />

					<p:commandButton value="Pedido" 
									action="#{obraMB.pedido()}"
									ajax="false" 
									id="btNovoPedido" />
						
					<p:commandButton value="Imprimir" 
									action="#{obraMB.imprimir()}" 
									ajax="false"
									id="bt_imprimir"/>

				</div>
				
				<br />
				<table class="tablePesquisa">
					<tr>
						<td><h:outputLabel value="Inicio" /></td>
						<td><p:calendar value="#{obraMB.dataInicioPesquisa}"
								locale="pt_BR" size="10" showOtherMonths="true"
								pattern="dd/MM/yyyy" id="dataInicioPesq">
							</p:calendar></td>
						
					</tr>
					
					<tr>						
						<td><h:outputLabel value="Término" /></td>
						<td><p:calendar value="#{obraMB.dataTerminoPesquisa}"
								locale="pt_BR" size="10" showOtherMonths="true"
								pattern="dd/MM/yyyy" id="dataTerminoPesq">

							</p:calendar></td>					
					</tr>
					
					<tr>					
						<td><h:outputLabel value="Obra" /></td>
						<td><p:inputText value="#{obraMB.numeroObra}" /></td>			
					</tr>

					<tr>					
						<td><h:outputLabel value="Responsável" /></td>		
						<td><p:selectOneMenu value="#{obraMB.idPessoaResponsavelPesquisa}"
								id="select_pessoa_pesquisa"
								disabled="#{obraMB.gerente}">
								<f:selectItems value="#{obraMB.listaResponsaveis}" />
							</p:selectOneMenu></td>
					</tr>
					
					<tr>
						<td><p:commandButton value="Buscar"	action="#{obraMB.pesquisar()}" ajax="false" /></td>
					</tr>

				</table>

			</p:fieldset>

			<br />

			<h:panelGroup id="pnl_list_obras">
				<p:dataTable value="#{obraMB.listEntity}" var="obra"
					paginator="true" rows="10" paginatorPosition="bottom"
					rendered="#{obraMB.listEntity.size() != 0}">
					<p:column>
						<f:facet name="header">
							<h:outputText value="Cód." />
						</f:facet>
						<h:outputText value="#{obra.id}" />
					</p:column>

					<p:column>
						<f:facet name="header">
							<h:outputText value="Responsável" />
						</f:facet>
						<h:outputText value="#{obra.pessoa.nome}" />
					</p:column>

					<p:column>
						<f:facet name="header">
							<h:outputText value="Descrição" />
						</f:facet>
						<h:outputText value="#{obra.descricao}" />
					</p:column>

					<p:column>
						<f:facet name="header">
							<h:outputText value="Estágio" />
						</f:facet>
						<h:outputText
							value="#{obra.listaEstagios.get(0).estagio.toString()}" />
					</p:column>

					<p:column>
						<f:facet name="header">
							<h:outputText value="Valor Est." title="Valor Estágio" />
						</f:facet>
						<h:outputText value="#{obra.listaEstagios.get(0).valorTotal}">
							<f:convertNumber currencySymbol="R$" type="currency" />
						</h:outputText>
					</p:column>

					<p:column>
						<f:facet name="header">
							<h:outputText value="Valor Prev." title="Valor Previsto" />
						</f:facet>
						<h:outputText value="#{obra.valorPrevisto}">
							<f:convertNumber currencySymbol="R$" type="currency" />
						</h:outputText>
					</p:column>

					<p:column>
						<f:facet name="header">
							<h:outputText value="Ações" />
						</f:facet>

						<h:commandLink
							rendered="#{obraMB.gerente || obraMB.administrator}"
							action="#{obraMB.editar()}" title="Editar">
							<f:setPropertyActionListener target="#{obraMB.obra}"
								value="#{obra}" />
							<h:graphicImage value="/images/editar.png"
								styleClass="buttonEditDeletSearch" />
						</h:commandLink>

						<h:commandLink 	target="_blank" title="Visualizar" action="#{obraMB.visualizar(obra)}">
							<h:graphicImage value="/images/visualizar.png"
								styleClass="buttonEditDeletSearch" />
						</h:commandLink>

						<p:commandLink
							rendered="#{obraMB.gerente || obraMB.administrator}"
							oncomplete="cdRemoveObra.show()" title="Excluir">
							<f:setPropertyActionListener target="#{obraMB.obra}"
								value="#{obra}" />
							<h:graphicImage value="/images/excluir.png"
								styleClass="buttonEditDeletSearch" />
						</p:commandLink>

					</p:column>
				</p:dataTable>
			</h:panelGroup>
		</h:form>

		<h:form>
			<p:confirmDialog message="Deseja realmente excluir?" header="Excluir"
				severity="alert" modal="true" widgetVar="cdRemoveObra">
				<p:outputPanel>
					<h:form>
						<p:commandButton action="#{obraMB.deletar()}" 
										 value="Sim"
										 ajax="false">

						</p:commandButton>
						<p:commandButton value="Não" onclick="cdRemoveObra.hide()" />
					</h:form>
				</p:outputPanel>
			</p:confirmDialog>
		</h:form>

	</ui:define>

</ui:composition>

</html>